<?php

class user_log extends main{

    function __construct(){
        parent::__construct();
        $this->loadModel('g5_user_login_log');
    }

    function index(){
        $string = isset($_GET[2]) ? $_GET[2] : '';
        $page   = isset($_GET[3]) ? $_GET[3] : 1;
        $where = $result = array();
        $search = isset($_POST['s']) ? $_POST['s'] : array();
        $total = $users = 0;
        $pageSize = 10;
        if($string != ''){
            $search = unserialize(base64_decode($string));
        }

        if( !empty($search['user_id'])){
            $where['user_id'] = trim($search['user_id']);
        }
        if( !empty($search['login_stime'])){
            $where['user_login_time>='] = strtotime(trim($search['login_stime']));
        }else{
            $search['login_stime'] = date('Y-m-d');
            $where['user_login_time>='] = strtotime($search['login_stime']);
        }
        if( !empty($search['login_etime'])){
            $where['user_login_time<='] = strtotime(trim($search['login_etime']) .' 23:59:59');
        }else{
            $search['login_etime'] = date('Y-m-d');
            $where['user_login_time<='] = strtotime($search['login_etime'] . ' 23:59:59');
        }
        if($search || $string){
            $result = $this->g5_user_login_log->limit($pageSize, ($page-1)*$pageSize)->getAll('*', $where);
            $total  = $this->g5_user_login_log->getCount('*', $where);
            $sum = $this->g5_user_login_log->count('user_id', 'user_id', true)->count('user_login_ip','login_ip',true)->_compile_select()->fetch_one();
            $this->sum = $sum;
        }
        $this->page($page, $total, base64_encode(serialize($search)), $pageSize);
        $this->result = $result;
        $this->search = $search;
    }
}

?>